﻿using System;
using System.Collections.Generic;
using System.Collections;

namespace Diary.BAL
{
    static public class BALTools
    {
        static public string toString(this Hashtable ht, string key, string dv = "")
        {
            if (ht == null) return dv;
            if (!ht.Contains(key)) return dv;
            if (ht[key] == null) return dv;
            return ht[key].ToString();
        }

        static public int toInt(this Hashtable ht, string key, int dv=0)
        {
            string str_v = ht.toString(key);
            if (string.IsNullOrEmpty(str_v)) return dv;
            int.TryParse(str_v, out dv);
            return dv;
        }

        static public DateTime toDateTime(this Hashtable ht, string key)
        {
            DateTime dv = DateTime.MinValue;
            string str_v = ht.toString(key);
            if (string.IsNullOrEmpty(str_v)) return dv;
            DateTime.TryParse(str_v, out dv);
            return dv;
        }
        static public bool toBool(this Hashtable ht, string key, bool dv = false)
        {
            string str_v = ht.toString(key);
            if (string.IsNullOrEmpty(str_v)) return dv;
            return str_v == "1";
        }

    }
}
